package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.apis.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "频道管理-AdChannel",description = "频道管理系统")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    AdChannelService adChannelService;
    /**
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/list")
    @ApiOperation("条件分页查询相关信息")
    public ResponseResult findPageListMsg(@RequestBody ChannelDto dto) {
        System.out.println("进入admin查询层");
        return adChannelService.findPageListMsg(dto);
    }

    /**
     * 新增
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("/save")
    @ApiOperation("新增频道信息")
    public ResponseResult insert(@RequestBody AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }

    /**
     * 修改
     * @param adChannel
     * @return
     */
    @Override
    @PutMapping("/update")
    @ApiOperation("更新频道信息")
    public ResponseResult updata(@RequestBody AdChannel adChannel) {
        return adChannelService.updata(adChannel);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    @DeleteMapping("/del/{id}")
    @ApiOperation("删除频道信息")
    public ResponseResult delete(Integer id) {
        return adChannelService.delete(id);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    @PutMapping("/moveUp/{id}")
    @ApiOperation("频道上移")
    public ResponseResult moveUp(@PathVariable("id") Integer id) {
        return adChannelService.moveUp(id);
    }

    @Override
    @PutMapping("/moveDown/{id}")
    @ApiOperation("频道下移")
    public ResponseResult moveDown(@PathVariable("id") Integer id) {
        return adChannelService.moveDown(id);
    }

    @ApiOperation("文章内容查看")
    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }


}
